package dome2collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class collectionDome3 {
    public static void main(String[] args) {
        //目标：Collection集合的三种遍历方式：
        //1.迭代器：Iterator
        //2.foreach  增强for循环
        //for（元素数据类型 变量名：集合名{ }
        //3.lambda
        Collection<String> list=new ArrayList();
        list.add("chen");
        list.add("shi");
        list.add("yu");
        list.add("yuan");
        System.out.println(list);//[chen, shi, yu, yuan]

        Iterator<String> it = list.iterator();//创建迭代器对象
//        while(it.hasNext()){   while循环遍历
        //hasnext()判断是否还有下一个元素
//            String s = it.next();
//            System.out.println(s);
//        }

        for(String s:list) {//for循环遍历  代码简洁明了
            System.out.println(s);
        }
        String []users={"admin","root","chen"};
        for (String user : users) {
            System.out.println(user);
        }





    }
}
